package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.CoinService;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.*;
import com.lanchetech.bean.vo.CoinProductVO;
import com.lanchetech.entity.CoinOrder;
import com.lanchetech.entity.CoinProduct;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(value = "积分商城管理接口", tags = "积分商城管理接口")
@RequestMapping("/api/coin")
@RestController
public class CoinController {

    @Autowired
    CoinService coinService;

    @OperatorLog("编辑积分商品")
    @ApiOperation("编辑积分商品")
    @PreAuthorize("hasAuthority('marketing.coin.coin-product.edit.auth')")
    @PostMapping("/editCoinProduct")
    public BaseResp editCoinProduct(@RequestBody CoinProduct coinProduct) {
        return coinService.editCoinProduct(coinProduct);
    }

    @ApiOperation("获取积分商品详情")
    @PreAuthorize("hasAuthority('marketing.coin.coin-product.edit.auth')")
    @GetMapping("/getCoinProductDetail")
    public ResultData<CoinProductVO> getCoinProductDetail(@RequestParam("id") Long id) {
        return coinService.getCoinProductDetail(id);
    }

    @ApiOperation("获取积分商品分页")
    @PreAuthorize("hasAuthority('marketing.coin.coin-product')")
    @PostMapping("/getCoinProductPage")
    public ResultData<BasePageResp<CoinProductResp>> getCoinProductPage(@RequestBody PageReq req) {
        return coinService.getCoinProductPage(req);
    }

    @OperatorLog("删除积分商品")
    @ApiOperation("删除积分商品")
    @PreAuthorize("hasAuthority('marketing.coin.coin-product.edit.auth')")
    @GetMapping("/deleteCoinProduct")
    public BaseResp deleteCoinProduct(@RequestParam("id") Long id) {
        return coinService.deleteCoinProduct(id);
    }



    @ApiOperation("获取积分商品订单分页")
    @PreAuthorize("hasAuthority('marketing.coin.coin-order')")
    @PostMapping("/getCoinOrderPage")
    public ResultData<BasePageResp<CoinOrderResp>> getCoinOrderPage(@RequestBody PageReq req) {
        return coinService.getCoinOrderPage(req);
    }

    @ApiOperation("获取积分商品订单详情")
    @PreAuthorize("hasAuthority('marketing.coin.coin-order.edit.auth')")
    @GetMapping("/getCoinOrderDetail")
    public ResultData<CoinOrderResp> getCoinOrderDetail(@RequestParam("id") Long id) {
        return coinService.getCoinOrderDetail(id);
    }

    @OperatorLog("积分商品发货填写快递物流信息")
    @ApiOperation("积分商品发货填写快递物流信息")
    @PreAuthorize("hasAuthority('marketing.coin.coin-order.edit.auth')")
    @PostMapping("/editCoinOrderLogistics")
    public BaseResp editCoinOrderLogistics(@RequestBody CoinOrder req) {
        return coinService.editCoinOrderLogistics(req);
    }

}
